package cn.iocoder.mall.shop.service.service.rpc.service.impl;

import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.utils.common.util.ObjectUtils;
import cn.iocoder.mall.shop.api.RpcShopCategoryRelationshipService;
import cn.iocoder.mall.shop.api.pojo.CategoryPageDTO;
import cn.iocoder.mall.shop.api.pojo.ShopCategoryDTO;
import cn.iocoder.mall.shop.service.service.IShopCategoryService;
import cn.iocoder.mall.shop.service.service.IShopService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :ssf
 * @date :2019/11/26
 * 商铺条目与商品关联关系实现类
 */
@Service
@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.RpcShopCategoryRelationshipService.version}")
public class RpcShopCategoryRelationshipServiceImpl implements RpcShopCategoryRelationshipService {

    @Autowired
    IShopService iShopService;

    @Autowired
    IShopCategoryService categoryService;

    @Override
    public void saveOneCategoryAndSpuId(long spuId, String categoryId, String shopId) {

        iShopService.saveCategoryAndSpuId(spuId,categoryId,shopId);
    }

    @Override
    public void deleteOneCategoryAndSpuId(long spuId) {
        iShopService.deleteCategoryAndSpuId(spuId);
    }

    @Override
    public void deleteListCategoryAndSpuId(List<String> spuIds) {
        iShopService.deleteCategoryAndSpuIds(spuIds);
    }

    @Override
    public CommonResult<ShopCategoryDTO> getOneShopCategoryBySpuId(Long id) {
        return CommonResult.success(ObjectUtils.copyObject(categoryService.getOneShopCategoryBySpuId(id),ShopCategoryDTO.class));
    }

    @Override
    public CommonResult<CategoryPageDTO> pageListOfCategory(CategoryPageDTO dto) {

        Page page=new Page(dto.getPageNo(),dto.getPageSize());

        CategoryPageDTO categoryPageDTO=new CategoryPageDTO();
        IPage<Long> iPage=categoryService.pageListOfCategory(page,dto.getEntryId());
        categoryPageDTO.setIds(iPage.getRecords());
        categoryPageDTO.setTotal(iPage.getTotal());
        categoryPageDTO.setCurrent(iPage.getCurrent());

        return CommonResult.success(categoryPageDTO);
    }
}
